package org.batatasframework.support.database.sql;

import org.batatasframework.support.database.metadatas.FieldMetadata;
import org.batatasframework.support.database.sql.field.FieldSourcable;

public class FieldFragment implements FieldSourcable{
	
	/**
	 * 数据库表的别名
	 */
	protected final TableInstance targetTable;
	
	protected final FieldMetadata fieldMetadata;
	
	protected final String columnName;

	public FieldFragment(TableInstance targetTable, FieldMetadata fieldMetadata) {
		this.targetTable = targetTable;
		this.fieldMetadata = fieldMetadata;
		this.columnName = targetTable.getAlias() + '.' + fieldMetadata.getcolumnName();
	}
	
	@Override
	public FieldMetadata getSourceField() {
		return fieldMetadata;
	}
	
	@Override
	public TableInstance getTargetTable() {
		return targetTable;
	}
	
	@Override
	public String getColumnName() {
		return columnName;
	}
}
